//
//  CombinatioanBusinessDetailViewController.m
//  HAODE
//
//  Created by LiYinDi on 16/1/21.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "CombinatioanBusinessDetailViewController.h"
#import "CombinationBusinessDetailCell.h"
#import "HttpRequest.h"
#import "UIImageView+WebCache.h"
#import "PlaceOrderSpecTableViewCell.h"
#import "Masonry.h"
#import "SelectedGoodNewViewController.h"
#import "BusinessOrderExtAddViewController.h"
#import "BusinessCombinationAddViewController.h"
#import "HAODEsingleton.h"
@interface CombinatioanBusinessDetailViewController ()<CombinationBusinessDetailCellDelegate,PlaceOrderSpecCellDelegate>
{
    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;

    NSMutableArray *subItemIDArray;
    NSMutableArray *subItemNameArray;
    NSMutableArray *subItemUrlArray;
   //  NSMutableArray *subItemUrlHalfArray;
    NSMutableArray *subItemStockCountArray;
    NSMutableArray *subHasSpecArray;
    NSMutableArray *subSalePriceArray;
    NSMutableArray *subItemTypeArray;
    //NSMutableArray *subAllCountArray;
    NSMutableArray *subItemCodeArray;
    HAODEsingleton*commdity;
//  NSString *itemTypeCodeStr;
    
    NSMutableArray *specNameArray;
    NSMutableArray *specPriceArray;
    NSMutableArray *specIDArray;
    NSMutableArray *specStockCountArray;
    
    NSInteger subCellTag;
    
    NSMutableArray *topImageArray;
    NSMutableArray *topImageHalfArray;
}
@end

@implementation CombinatioanBusinessDetailViewController
-(void)viewWillAppear:(BOOL)animated
{
//    UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 20)];
//    statusBarView.backgroundColor=[UIColor clearColor];
//    [self.view addSubview:statusBarView];
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
//  [[UIApplication sharedApplication] setStatusBarHidden:TRUE];
    [self initUI];
    [self setImageScrollView];
    commdity=[HAODEsingleton shared];
    _titleLabel.text=_titleStr;
    _titleContentLabel.text=_detailStr;
    // [_productImageView setImageWithURL:[NSURL URLWithString:[_imageListArray objectAtIndex:0] ]];
    
   [self setNavigation];
    _PageIndex=0;
    [self loadItemNextPage:_PageIndex];

}
-(void)setImageScrollView
{
    for (UIView *v in _titleImageScrollView.subviews) {
        [v removeFromSuperview];
    }
    topImageArray = [NSMutableArray arrayWithCapacity:[self.imageListArray count]];
    topImageHalfArray= [NSMutableArray arrayWithCapacity:[self.imageListArray count]];
    
    for (NSDictionary *dic in self.imageListArray) {
        
        [topImageArray addObject:[dic objectForKey:@"imageUrlFull"]];
        [topImageHalfArray addObject:[dic objectForKey:@"imageUrl"]];
    }
    
   // [_productImageView setImageWithURL:[NSURL URLWithString:[array objectAtIndex:0] ]];

    [_titleImageScrollView setContentSize:CGSizeMake(ScreenWidth * topImageArray.count, 0)];
    
    
    [_titleImageScrollView setPagingEnabled:YES];
    
    
    [_titleImageScrollView setShowsVerticalScrollIndicator:NO];
    [_titleImageScrollView setShowsHorizontalScrollIndicator:NO];
    
    for (int i =0; i<topImageArray.count; i++)
    {
        UIImageView *imageView= [[UIImageView alloc] initWithFrame:CGRectMake(i * ScreenWidth,0,ScreenWidth,_titleImageScrollView.frame.size.height)] ;
        [imageView setImageWithURL:[NSURL URLWithString:[topImageArray objectAtIndex:i] ]];
        
             [_titleImageScrollView addSubview:imageView];
       
    }
    
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    if (scrollView==_titleImageScrollView) {
        
        CGFloat pageWidth = scrollView.frame.size.width;
        int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
        [_titleImageScrollView setContentOffset:CGPointMake(pageWidth*page, 0)];
        
        // NSLog(@"page///====%d",page);
    }
    
}





- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setAutolayout];
    // Do any additional setup after loading the view from its nib.
}
-(void)initUI
{
    subItemIDArray=[NSMutableArray array];
    subItemNameArray=[NSMutableArray array];
    subItemUrlArray=[NSMutableArray array];
    subItemTypeArray=[NSMutableArray array];
   // subItemUrlHalfArray=[NSMutableArray array];
    subItemStockCountArray=[NSMutableArray array];
    subHasSpecArray=[NSMutableArray array];
    subSalePriceArray=[NSMutableArray array];
   // subAllCountArray=[NSMutableArray array];
    subItemCodeArray=[NSMutableArray array];
    
    specPriceArray=[NSMutableArray array];
    specNameArray=[NSMutableArray array];
    specIDArray=[NSMutableArray array];
    specStockCountArray=[NSMutableArray array];
    
    [_alphaview setBackgroundColor:[Global parseColor:@"#66000000"]];
    [_totalView setBackgroundColor:[Global parseColor:@"#66000000"]];
    [_totalCountView setBackgroundColor:[Global parseColor:@"#E01F3536"]];
    
    _cornerCountLabel.layer.cornerRadius=10;
    _cornerCountLabel.layer.masksToBounds=YES;
    _specImageView.layer.cornerRadius=10.0f;
    _specImageView.layer.masksToBounds=YES;
    
    [_specView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left) ;
        make.right.equalTo(self.view.mas_right) ;
        make.top.equalTo(@2000) ;
        make.bottom.equalTo(self.view.mas_bottom);
    }];

     [self setCornerCountLabelText];
}
-(void) loadItemNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _TotalCount<=subItemIDArray.count)
        return;
    if(oldPageNum == 0){
        [subItemIDArray removeAllObjects];
        [_tableView reloadData];
    }
    _PageIndex=oldPageNum+1;
    [self requestItemList: _PageIndex pageSize:20];
}
-(void)requestItemList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:_cbIdStr forKey:@"cbId"];
   
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/Combination/ItemList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
       //  NSLog(@"conbinationList－－－－－－－%@",severDataDict.dataDict);
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                _TotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                
                if (_TotalCount%20!=0) {
                    _TotalPage=_TotalCount/20+1;
                }
                else if (_TotalCount%20==0)
                {
                    _TotalPage=_TotalCount/20;
                }

                NSMutableArray * mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
               //   NSLog(@"mItemsArray===%@",[[mItemsArray objectAtIndex:i] objectForKey:@"imageUrlFull"]);
                if ( mItemsArray.count>0) {
                    for (int i=0; i< mItemsArray.count; i++) {
                        [subItemCodeArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"itemCode"]];
                        [subItemIDArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"itemId"]];
                        [subItemNameArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"itemName"]];
                        [subItemUrlArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"imageUrlFull"]];
                        [subItemTypeArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"itemType"]];
                        //[subItemUrlHalfArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"imageUrl"]];
                        NSString *maxPriceStr=[Global floatConvertPercentile:[[[mItemsArray objectAtIndex:i] objectForKey:@"maxPrice"] floatValue]];
                        NSString *minPriceStr=[Global floatConvertPercentile:[[[mItemsArray objectAtIndex:i] objectForKey:@"minPrice"] floatValue]];
                        NSString *salePrice=[NSString stringWithFormat:@"%0.02f",[[[mItemsArray objectAtIndex:i] objectForKey:@"salePrice"] floatValue]];
                        
                        if ([maxPriceStr floatValue]==[minPriceStr floatValue]) {
                            
                            [subSalePriceArray addObject:salePrice];
                        }
                        else{
                            
                            NSString *str=[NSString stringWithFormat:@"%@~%@",minPriceStr,maxPriceStr];
                            
                            [subSalePriceArray addObject:str];
                        }
                        [subHasSpecArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"hasSpec"]];
                        [subItemStockCountArray addObject:[[mItemsArray objectAtIndex:i] objectForKey:@"invQty"]];
                        
                    }
                }
                    [_tableView reloadData];
//                [_scrollView setContentSize:CGSizeMake(0, _tableView.frame.origin.y+ 110*subItemIDArray.count)];
//                [_scrollView setScrollEnabled:YES];
                [_tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(_scrollContentView.mas_left) ;
                    make.right.equalTo(_scrollContentView.mas_right) ;
                    make.top.equalTo(_topView.mas_bottom).with.offset(10) ;
                    make.bottom.equalTo(_topView.mas_bottom).with.offset(110*subItemCodeArray.count+40);
                }];
                if (subItemCodeArray.count>=3) {
                    
               
               
                }
                else
                {
                    

                }
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_tableView) {
        return 110;
    }
    else
    {
        return 45;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
     if (tableView==_tableView) {
    return 40;
     }
    else
        return 0;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
     if (tableView==_tableView) {
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 40)];
    view.backgroundColor=[UIColor whiteColor];
    UILabel *textLabel=[[UILabel alloc] init];
    textLabel.text=@"组合商品";
    textLabel.textColor=[UIColor colorWithRed:120.0/255.0 green:120.0/255.0 blue:120.0/255.0 alpha:1.0];
    textLabel.textAlignment=NSTextAlignmentCenter;
    textLabel.frame=CGRectMake(0, 0, view.frame.size.width, view.frame.size.height-1);
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(5,view.frame.size.height-1, view.frame.size.width-10, 1)];
    lineLabel.backgroundColor=[UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:240.0/255.0];
    [view addSubview:textLabel];
    [view addSubview:lineLabel];
    return view;
     }
    else
        return nil;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==_tableView)
    return subItemIDArray.count;
    else
        return specIDArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_tableView) {
        
   
        
        static NSString * const  CombinationDetailCellIdentifier = @"CombinationDetailCellIdentifier";
        CombinationBusinessDetailCell *cell=( CombinationBusinessDetailCell *)[tableView dequeueReusableCellWithIdentifier: CombinationDetailCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"CombinationBusinessDetailCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
    cell.delegate=self;
        //  cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
        cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
        
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.outsideAddBtn.tag=indexPath.row;
    cell.addButton.tag=indexPath.row;
    cell.subtractButton.tag=indexPath.row;
    if (subItemUrlArray.count>0) {
        [cell.productImageView setImageWithURL:[NSURL URLWithString:[subItemUrlArray objectAtIndex:indexPath.row]]];
    }
    if (subItemNameArray.count>0) {
        [cell.productNameLabel setText:[subItemNameArray objectAtIndex:indexPath.row]];
    }
    if (subItemStockCountArray.count) {
        cell.saleCountLabel.text=[NSString stringWithFormat:@"库存%d件",[[subItemStockCountArray objectAtIndex:indexPath.row] intValue]];
    }
    if (subSalePriceArray.count>0) {
        if ([[subSalePriceArray objectAtIndex:indexPath.row]containsString:@"~"] ) {
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",[subSalePriceArray objectAtIndex:indexPath.row] ];
            
            
        }
        else
        {
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",[Global floatConvertPercentile:[[subSalePriceArray objectAtIndex:indexPath.row] floatValue]] ];
        }
        
    }
        if (subItemCodeArray.count>0) {
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
            NSArray *keyArray= [dict allKeys];
            int count=0.0;
            for (NSString *keyStr in keyArray) {
                if ([keyStr containsString:[subItemCodeArray objectAtIndex:indexPath.row]]) {
                    count=count+[[[dict objectForKey:keyStr] objectForKey:@"itemCount"] intValue];
                }
            }
            
            cell.countLabel.text=[NSString stringWithFormat:@"%d",count];
            if ([cell.countLabel.text intValue]>0) {
                cell.outsideAddBtn.hidden=YES;
                cell.countView.hidden=NO;
            }
            else
            {
                cell.countLabel.text=@"0";
                cell.outsideAddBtn.hidden=NO;
                cell.countView.hidden=YES;
            }
            
            
        }

   
        return cell;
    
    }
    else
    {
        static NSString * const  ResultTableViewCellIdentifier = @"PlaceOrderSpecTableViewCell";
        PlaceOrderSpecTableViewCell *cell=( PlaceOrderSpecTableViewCell *)[tableView dequeueReusableCellWithIdentifier: ResultTableViewCellIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"PlaceOrderSpecTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate=self;
        if (specNameArray.count>0) {
            cell.contentLabel.text=[NSString stringWithFormat:@"%@  ¥%@",[specNameArray objectAtIndex:indexPath.row],[Global floatConvertPercentile:[[specPriceArray objectAtIndex:indexPath.row] floatValue]]];
            }
        if (specIDArray.count>0) {
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
            NSString *keyStr=[NSString stringWithFormat:@"%@%@",[subItemCodeArray objectAtIndex:subCellTag],[specIDArray objectAtIndex:indexPath.row]];
            NSString *str=@"";
//            if ([[dict objectForKey:keyStr ]objectForKey:@"itemCount"]) {
//                str=[[dict objectForKey:keyStr ]objectForKey:@"itemCount"];
//                cell.countLabel.text=str;
//                cell.subtractButton.hidden=NO;
//                cell.countLabel.hidden=NO;
//            }
//            else
//            {
//                cell.countLabel.text=@"";
//                cell.subtractButton.hidden=YES;
//                cell.countLabel.hidden=YES;
//            }
//
        }
//
//        
//        cell.subtractButton.tag=indexPath.row;
        return cell;
        

    }
}
#pragma mark tableviewcelldelegate
-(void)CellAddBtnClick:(NSUInteger)tag
{
    subCellTag=tag;
    if ([[subHasSpecArray objectAtIndex:tag] isEqualToString:@"N"]) {
        NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:tag inSection:0];
        UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath1];
        CombinationBusinessDetailCell *subCell=( CombinationBusinessDetailCell *)cell;
        
          if ([subCell.countLabel.text intValue]<[[subItemStockCountArray objectAtIndex:tag] intValue]) {
        subCell.countLabel.text=[NSString stringWithFormat:@"%d",subCell.countLabel.text.intValue+1];
//        if ([[subHasSpecArray objectAtIndex:tag] isEqualToString:@"N"]) {
//            
//            _totalLabel.text=[NSString stringWithFormat:@"%0.02f",[_totalLabel.text floatValue]+[[subSalePriceArray objectAtIndex:tag] floatValue]];
//        }
             
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
        NSMutableDictionary *contentDict=[NSMutableDictionary dictionary];
        
              [contentDict setObject:[subItemCodeArray objectAtIndex:tag] forKey:@"itemCode"];
              [contentDict setObject:[subItemIDArray objectAtIndex:tag] forKey:@"itemID"];
              [contentDict setObject:[subItemNameArray objectAtIndex:tag] forKey:@"itemName"];
              [contentDict setObject:[subItemUrlArray objectAtIndex:tag] forKey:@"itemUrl"];
              [contentDict setObject:[subItemTypeArray objectAtIndex:tag] forKey:@"itemType"];
              [contentDict setObject:[subSalePriceArray objectAtIndex:tag] forKey:@"itemPrice"];
              [contentDict setObject:subCell.countLabel.text forKey:@"itemCount"];
              [contentDict setObject:[subItemStockCountArray objectAtIndex:tag] forKey:@"itemStockCount"];
              
              [contentDict setObject:@"" forKey:@"itemSpecName"];
              [contentDict setObject:@"" forKey:@"itemSpecID"];
              [contentDict setObject:@"" forKey:@"itemSpecStockCount"];

        [dict setObject:contentDict forKey:[subItemCodeArray objectAtIndex:tag]];
        [userDefaults setObject:dict forKey:@"PLACEORDER"];
        [userDefaults synchronize];
       [self setCornerCountLabelText];
        //[self setUserDefaults];
        }
          else
          {
              UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"已超出商品库存量" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
              [alert show];
          }
 
    }
    else{
        [self requestSpecList:[subItemIDArray objectAtIndex:tag]];
        [UIView animateWithDuration:0.5f animations:^
         {
             [_specView mas_remakeConstraints:^(MASConstraintMaker *make) {
                 make.left.equalTo(self.view.mas_left) ;
                 make.right.equalTo(self.view.mas_right) ;
                 make.top.equalTo(self.view.mas_top) ;
                 make.bottom.equalTo(self.view.mas_bottom);
             }];
             
         }completion:^(BOOL finished) {
             [_specImageView setImageWithURL:[NSURL URLWithString:[subItemUrlArray objectAtIndex:tag]]];
             [_specProductNameLabel setText:[subItemNameArray objectAtIndex:tag]];
             _specPriceScopeLabel.text=[NSString stringWithFormat:@"¥%@",[subSalePriceArray objectAtIndex:tag] ];
             _specCountLabel.text=[NSString stringWithFormat:@"库存%d件",[[subItemStockCountArray objectAtIndex:tag] intValue]];
             
         }];
        
        
    }
    
}
-(void)CellSubtractBtnClick:(NSUInteger)tag
{
    subCellTag=tag;
    if ([[subHasSpecArray objectAtIndex:tag] isEqualToString:@"N"]) {
        
        NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:tag inSection:0];
        UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath1];
        CombinationBusinessDetailCell *subCell=( CombinationBusinessDetailCell *)cell;
        
        subCell.countLabel.text=[NSString stringWithFormat:@"%d",subCell.countLabel.text.intValue-1];
        
        if (subCell.countLabel.text.intValue>0)
        {
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
            
            NSMutableDictionary *contentDict=[NSMutableDictionary dictionary];
            
            [contentDict setObject:[subItemCodeArray objectAtIndex:tag] forKey:@"itemCode"];
            [contentDict setObject:[subItemIDArray objectAtIndex:tag] forKey:@"itemID"];
            [contentDict setObject:[subItemNameArray objectAtIndex:tag] forKey:@"itemName"];
            [contentDict setObject:[subItemUrlArray objectAtIndex:tag] forKey:@"itemUrl"];
            [contentDict setObject:[subItemTypeArray objectAtIndex:tag] forKey:@"itemType"];
            [contentDict setObject:[subSalePriceArray objectAtIndex:tag] forKey:@"itemPrice"];
            [contentDict setObject:subCell.countLabel.text forKey:@"itemCount"];
            [contentDict setObject:[subItemStockCountArray objectAtIndex:tag] forKey:@"itemStockCount"];
            
            [contentDict setObject:@"" forKey:@"itemSpecName"];
            [contentDict setObject:@"" forKey:@"itemSpecID"];
            [contentDict setObject:@"" forKey:@"itemSpecStockCount"];
            [dict setObject:contentDict forKey:[subItemCodeArray objectAtIndex:tag]];
            [dict setObject:contentDict forKey:[subItemCodeArray objectAtIndex:tag]];
            
            [userDefaults setObject:dict forKey:@"PLACEORDER"];
            [userDefaults synchronize];
            
        }
        if (subCell.countLabel.text.intValue==0)
        {
            subCell.countView.hidden=YES;
            subCell.outsideAddBtn.hidden=NO;
            subCell.countLabel.text=@"";
            
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
            [dict removeObjectForKey:[subItemCodeArray objectAtIndex:tag]];
            
            
            [userDefaults setObject:dict forKey:@"PLACEORDER"];
            [userDefaults synchronize];
            
        }
        // _totalLabel.text=[NSString stringWithFormat:@"%0.02f",[_totalLabel.text floatValue]-[[subSalePriceArray objectAtIndex:tag] floatValue]];
        //[self setUserDefaults];
        [self setCornerCountLabelText];
    }
    else{
        [self requestSpecList:[subItemIDArray objectAtIndex:tag]];
        [UIView animateWithDuration:0.5f animations:^
         {
             [_specView mas_remakeConstraints:^(MASConstraintMaker *make) {
                 make.left.equalTo(self.view.mas_left) ;
                 make.right.equalTo(self.view.mas_right) ;
                 make.top.equalTo(self.view.mas_top) ;
                 make.bottom.equalTo(self.view.mas_bottom);
             }];
             
         }completion:^(BOOL finished) {
             [_specImageView setImageWithURL:[NSURL URLWithString:[subItemUrlArray objectAtIndex:tag]]];
             [_specProductNameLabel setText:[subItemNameArray objectAtIndex:tag]];
             _specPriceScopeLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[subSalePriceArray objectAtIndex:tag] floatValue]];
             _specCountLabel.text=[NSString stringWithFormat:@"库存%d件",[[subItemStockCountArray objectAtIndex:tag] intValue]];
             
             
         }];
        
    }
    
}
-(void)CellOutsideAddBtnClick:(NSUInteger)tag
{
   if ([[subItemStockCountArray objectAtIndex:tag] intValue]>0) {
        subCellTag=tag;
        if ([[subHasSpecArray objectAtIndex:tag] isEqualToString:@"N"]) {
            NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:tag inSection:0];
            UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath1];
            CombinationBusinessDetailCell *subCell=( CombinationBusinessDetailCell *)cell;
            subCell.countView.hidden=NO;
            subCell.outsideAddBtn.hidden=YES;
            subCell.countLabel.text=@"1";
            
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
            NSMutableDictionary *contentDict=[NSMutableDictionary dictionary];
            [contentDict setObject:[subItemCodeArray objectAtIndex:tag] forKey:@"itemCode"];
            [contentDict setObject:[subItemIDArray objectAtIndex:tag] forKey:@"itemID"];
            [contentDict setObject:[subItemNameArray objectAtIndex:tag] forKey:@"itemName"];
            [contentDict setObject:[subItemUrlArray objectAtIndex:tag] forKey:@"itemUrl"];
            [contentDict setObject:[subItemTypeArray objectAtIndex:tag] forKey:@"itemType"];
            [contentDict setObject:[subSalePriceArray objectAtIndex:tag] forKey:@"itemPrice"];
            [contentDict setObject:subCell.countLabel.text forKey:@"itemCount"];
            [contentDict setObject:[subItemStockCountArray objectAtIndex:tag] forKey:@"itemStockCount"];
            
            [contentDict setObject:@"" forKey:@"itemSpecName"];
            [contentDict setObject:@"" forKey:@"itemSpecID"];
            [contentDict setObject:@"" forKey:@"itemSpecStockCount"];
            [dict setObject:contentDict forKey:[subItemCodeArray objectAtIndex:tag]];
            
            [userDefaults setObject:dict forKey:@"PLACEORDER"];
            [userDefaults synchronize];
            [self setCornerCountLabelText];

        }
        else
        {
            [self requestSpecList:[subItemIDArray objectAtIndex:tag]];
            [UIView animateWithDuration:0.5f animations:^
             {
                 [_specView mas_remakeConstraints:^(MASConstraintMaker *make) {
                     make.left.equalTo(self.view.mas_left) ;
                     make.right.equalTo(self.view.mas_right) ;
                     make.top.equalTo(self.view.mas_top) ;
                     make.bottom.equalTo(self.view.mas_bottom);
                 }];
                 
             }completion:^(BOOL finished) {
                 [_specImageView setImageWithURL:[NSURL URLWithString:[subItemUrlArray objectAtIndex:tag]]];
                 [_specProductNameLabel setText:[subItemNameArray objectAtIndex:tag]];
                 _specPriceScopeLabel.text=[NSString stringWithFormat:@"¥%0.02f",[[subSalePriceArray objectAtIndex:tag] floatValue]];
                 _specCountLabel.text=[NSString stringWithFormat:@"库存%d件",[[subItemStockCountArray objectAtIndex:tag] intValue]];
                 
                 NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:tag inSection:0];
                 UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath1];
                 CombinationBusinessDetailCell *subCell=( CombinationBusinessDetailCell *)cell;
                 subCell.countView.hidden=NO;
                 subCell.outsideAddBtn.hidden=YES;
                 
             }];
            
        }
        
   }
   else
   {
       UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"商品库存为0" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
       [alert show];
   }

 
}
-(void)requestSpecList:(NSString *)itemID
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:itemID forKey:@"itemId"];
    [Global showIndeterminateHud:@"加载中，请稍后。。。" delay:30 view:self.view];
   // NSLog(@"666===%@",param);
    [HttpRequest requestData:@"Product/GetProductDetail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
              //  NSLog(@"result///===%@",severDataDict.dataDict);
                NSMutableArray *dataArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"specList"]];
                [specPriceArray removeAllObjects];
                [specNameArray removeAllObjects];
                [specIDArray removeAllObjects];
                [specStockCountArray removeAllObjects];
                for (int i=0;i<dataArray.count;i++)
                {
                    [specPriceArray addObject:[[dataArray objectAtIndex: i] valueForKey:@"specPrice"]];
                    [specNameArray addObject:[[dataArray objectAtIndex: i] valueForKey:@"specName"]];
                    [specIDArray addObject:[[dataArray objectAtIndex: i] valueForKey:@"specId"]];
                    [specStockCountArray addObject:[[dataArray objectAtIndex: i] valueForKey:@"specInv"]];
                    
                }
              //  NSLog(@"specStockCountArray////===%@",specStockCountArray);
                [_specListTableView reloadData];
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    
                    //                    TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
                    //                    [self.navigationController pushViewController:detailViewController animated:YES];
                }
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
}
-(void)setCornerCountLabelText
{
    int cornerCount=0;
    // NSMutableArray *countArray=[NSMutableArray array];
    
    float totalValue=0.0;
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
    NSArray *keyArray=[dict allKeys];
    //
    //     NSLog(@"str//==%@", [dict objectForKey:[keyArray objectAtIndex:0]]);
    for (int i=0; i<keyArray.count; i++) {
        NSString *totalCountstr=[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemCount"];
        cornerCount=cornerCount+[totalCountstr intValue];
        
        NSString *countStr=[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemCount"];
        NSString *priceStr=[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemPrice"];
        
        totalValue=totalValue+[countStr intValue]*[priceStr floatValue];
        
    }
    _totalLabel.text=[Global floatConvertPercentile:totalValue];
    
    _cornerCountLabel.text=[NSString stringWithFormat:@"%lu",(unsigned long)cornerCount];
    if ([_cornerCountLabel.text intValue]==0) {
        _cornerCountLabel.hidden=YES;
    }
    else
    {
        _cornerCountLabel.hidden=NO;
    }
}
#pragma mark specTableviewCellDelegate
-(void)SpecCellSubtractBtnClick:(NSUInteger)tag
{
//    NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:tag inSection:0];
//    UITableViewCell *cell = [_specListTableView cellForRowAtIndexPath:indexPath1];
//    PlaceOrderSpecTableViewCell *specCell=( PlaceOrderSpecTableViewCell *)cell;
//    if (specCell.countLabel.text.intValue>0) {
//        specCell.countLabel.text=[NSString stringWithFormat:@"%d",specCell.countLabel.text.intValue-1];
//        
//        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//        NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
//        NSMutableDictionary *contentDict=[NSMutableDictionary dictionary];
//        
//        [contentDict setObject:[subItemCodeArray objectAtIndex:subCellTag] forKey:@"itemCode"];
//        [contentDict setObject:[subItemIDArray objectAtIndex:subCellTag] forKey:@"itemID"];
//        [contentDict setObject:[subItemStockCountArray objectAtIndex:subCellTag] forKey:@"itemStockCount"];
//        [contentDict setObject:[subItemNameArray objectAtIndex:subCellTag] forKey:@"itemName"];
//        [contentDict setObject:[subItemUrlArray objectAtIndex:subCellTag] forKey:@"itemUrl"];
//        [contentDict setObject:[subItemTypeArray objectAtIndex:subCellTag] forKey:@"itemType"];
//        [contentDict setObject:[specPriceArray objectAtIndex:tag] forKey:@"itemPrice"];
//        [contentDict setObject:specCell.countLabel.text forKey:@"itemCount"];
//        [contentDict setObject:[specNameArray objectAtIndex:tag] forKey:@"itemSpecName"];
//        [contentDict setObject:[specIDArray objectAtIndex:tag] forKey:@"itemSpecID"];
//        [contentDict setObject:[specStockCountArray objectAtIndex:tag] forKey:@"itemSpecStockCount"];
//        NSString *contentDictKey=[NSString stringWithFormat:@"%@%@",[subItemCodeArray objectAtIndex:subCellTag],[specIDArray objectAtIndex:tag]];
//        [dict setObject:contentDict forKey:contentDictKey];
//        
//        [userDefaults setObject:dict forKey:@"PLACEORDER"];
//        [userDefaults synchronize];
//    }
//    if (specCell.countLabel.text.intValue==0)
//    {
//        specCell.contentLabel.hidden=YES;
//        specCell.subtractButton.hidden=YES;
//        specCell.countLabel.text=@"";
//        
//        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
//        NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
//        NSString *contentDictKey=[NSString stringWithFormat:@"%@%@",[subItemCodeArray objectAtIndex:subCellTag],[specIDArray objectAtIndex:tag]];
//        [dict removeObjectForKey:contentDictKey];
//        
//        
//        [userDefaults setObject:dict forKey:@"PLACEORDER"];
//        [userDefaults synchronize];
//    }
    
    [self setCornerCountLabelText];
    
}
- (IBAction)specConfirmBtnClick:(id)sender {
    [UIView animateWithDuration:0.5f animations:^
     {
         [_specView mas_remakeConstraints:^(MASConstraintMaker *make) {
             make.left.equalTo(self.view.mas_left) ;
             make.right.equalTo(self.view.mas_right) ;
             make.top.equalTo(@2000) ;
             make.bottom.equalTo(self.view.mas_bottom);
         }];
         
     }completion:^(BOOL finished) {
         
     }];
    int total=0;
//    // float value=0.0;
//    for (int i=0; i<specNameArray.count; i++) {
//        NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:i inSection:0];
//        UITableViewCell *cell = [_specListTableView cellForRowAtIndexPath:indexPath1];
//        PlaceOrderSpecTableViewCell *specCell=( PlaceOrderSpecTableViewCell *)cell;
//        total=total+[specCell.countLabel.text intValue];
//    }
    NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:subCellTag inSection:0];
    UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath1];
    CombinationBusinessDetailCell *subCell=( CombinationBusinessDetailCell *)cell;
    subCell.countLabel.text=[NSString stringWithFormat:@"%d",total];
    
}
- (IBAction)specAlphaViewClick:(id)sender {
    [UIView animateWithDuration:0.5f animations:^
     {
         [_specView mas_remakeConstraints:^(MASConstraintMaker *make) {
             make.left.equalTo(self.view.mas_left) ;
             make.right.equalTo(self.view.mas_right) ;
             make.top.equalTo(@2000) ;
             make.bottom.equalTo(self.view.mas_bottom);
         }];
         
     }completion:^(BOOL finished) {
         
     }];
    int total=0;
    // float value=0.0;
//    for (int i=0; i<specNameArray.count; i++) {
//        NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:i inSection:0];
//        UITableViewCell *cell = [_specListTableView cellForRowAtIndexPath:indexPath1];
//        PlaceOrderSpecTableViewCell *specCell=( PlaceOrderSpecTableViewCell *)cell;
//        total=total+[specCell.countLabel.text intValue];
//    }
    NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:subCellTag inSection:0];
    UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath1];
    CombinationBusinessDetailCell *subCell=( CombinationBusinessDetailCell *)cell;
    subCell.countLabel.text=[NSString stringWithFormat:@"%d",total];
    //    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    //    NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDERDATA"]];
    //    NSMutableDictionary *contentDict=[NSMutableDictionary dictionary];
    //    [contentDict setObject:subCell.countLabel.text forKey:@"totalCount"];
    //    NSString *contentDictKey=[NSString stringWithFormat:@"%@",[subItemCodeArray objectAtIndex:subCellTag]];
    //    [dict setObject:contentDict forKey:contentDictKey];
    //
    //    [userDefaults setObject:dict forKey:@"PLACEORDERDATA"];
    //    [userDefaults synchronize];
}
- (IBAction)selectedGoodsBtnClick:(id)sender {
    SelectedGoodNewViewController *selectedGoodVC=[[SelectedGoodNewViewController alloc] init];//2.0{9个参数 少2个}
     selectedGoodVC.typeString=@"PLACEORDER";
    //selectedGoodVC.Whs=self.Whs;
    commdity.gengxin=@"";
    [self.navigationController pushViewController:selectedGoodVC animated:YES];

}
- (IBAction)confirmSubmit:(id)sender {
    float totalValue=0.0;
    NSMutableArray *imgArray=[NSMutableArray array];
    NSMutableArray *nameArray=[NSMutableArray array];
    NSMutableArray *salePriceArray=[NSMutableArray array];
    NSMutableArray *countArray=[NSMutableArray array];
    NSMutableArray *idArray=[NSMutableArray array];
    NSMutableArray *specName=[NSMutableArray array];
    NSMutableArray *specID=[NSMutableArray array];
    
    NSMutableArray *itemCodeArray=[NSMutableArray array];
    //NSMutableArray *allProductCountArray=[NSMutableArray array];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    // NSLog(@"rrr====%@",[userDefaults objectForKey:@"PLACEORDERDATA"]);
    NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults objectForKey:@"PLACEORDER"]];
    NSArray *keyArray= [dict allKeys];
    
    for (int i=0; i<keyArray.count; i++) {
        NSString *itemCodeStr=[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemCode"];
        
        [itemCodeArray addObject:itemCodeStr];
        [nameArray addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemName"]];
        //        NSLog(@"itemCodeStr////===%@",itemCodeStr);
        [imgArray addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemUrl"]];
        //          [productNameArray addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemCode"]];
        [salePriceArray addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemPrice"]];
        [countArray addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemCount"]];
        [specName addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemSpecName"]];
        [specID addObject:[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemSpecID"]];
        
        NSString *countStr=[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemCount"];
        NSString *priceStr=[[dict objectForKey:[keyArray objectAtIndex:i] ] objectForKey:@"itemPrice"];
        
        totalValue=totalValue+[countStr intValue]*[priceStr floatValue];
        
    }
    
    if (imgArray .count==0) {
        
        UIAlertView *alert1=[[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择商品" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        
        
        [alert1 show];
        
    }else{
        
      //直接下单
            
           commdity.userName=nil;
            BusinessOrderExtAddViewController *shouyinVC=[[BusinessOrderExtAddViewController alloc] init];//2.0{9个参数 少2个}
            shouyinVC.headImageFullArray=imgArray;
            shouyinVC.itemCodeArray=itemCodeArray;
            shouyinVC.specNameArray=specName;
            shouyinVC.itemIdArray= idArray;
            shouyinVC.itemNameArray=nameArray;
            shouyinVC.specIdArray=specID;
            shouyinVC.dealPriceArray=salePriceArray;
            shouyinVC.quantityArray=countArray;
            shouyinVC.TotalMoney=[NSString stringWithFormat:@"%0.02f",totalValue];
            [self.navigationController pushViewController:shouyinVC animated:YES];
            
    }
       
}
-(void)setAutolayout
{
    [_totalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left) ;
        make.right.equalTo(self.view.mas_right) ;
        make.height.equalTo(@50) ;
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    

    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(-64) ;
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(_totalView.mas_top);
    }];
    [_scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_scrollView);
        make.width.equalTo(_scrollView);
    }];
    [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_scrollContentView.mas_top) ;
        make.left.equalTo(_scrollContentView.mas_left);
        make.right.equalTo(_scrollContentView.mas_right);
        make.bottom.equalTo(_titleContentLabel.mas_bottom).with.offset(10);
    }];
    [_titleImageScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_topView.mas_top) ;
        make.left.equalTo(_topView.mas_left);
        make.right.equalTo(_topView.mas_right);
        make.height.equalTo(@220);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleImageScrollView.mas_bottom).with.offset(8) ;
        make.left.equalTo(_topView.mas_left).with.offset(10);
        make.right.equalTo(_topView.mas_right).with.offset(-10);
        make.height.equalTo(@20);
    }];
    
    [_titleContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).with.offset(3) ;
        make.left.equalTo(_topView.mas_left).with.offset(10);
        make.right.equalTo(_topView.mas_right).with.offset(-10);
        make.bottom.equalTo(_topView.mas_bottom).with.offset(-10);
    }];

    
    [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_topView.mas_top).with.offset(35);
        
        make.right.equalTo(_topView.mas_right).with.offset(-15);
        make.width.equalTo(@30);
        make.height.equalTo(@30);
    }];

    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_scrollContentView.mas_left) ;
         make.right.equalTo(_scrollContentView.mas_right);
        make.top.equalTo(_topView.mas_bottom).with.offset(10) ;
        make.bottom.equalTo(_topView.mas_bottom).with.offset(220+40);
    }];
    
    [_scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_tableView.mas_bottom);
    }];
  
    [_totalCountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_totalView.mas_left) ;
        make.right.equalTo(_submitConfirmBtn.mas_left) ;
        make.height.equalTo(@50) ;
        make.bottom.equalTo(_totalView.mas_bottom);
    }];
    [_submitConfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_totalView.mas_right) ;
        make.width.equalTo(@140) ;
        make.height.equalTo(@50) ;
        make.bottom.equalTo(_totalView.mas_bottom);
    }];
    [_totalCountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_totalView.mas_left) ;
        make.right.equalTo(_submitConfirmBtn.mas_left) ;
        make.height.equalTo(@50) ;
        make.bottom.equalTo(_totalView.mas_bottom);
    }];

    [_specView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left) ;
        make.right.equalTo(self.view.mas_right) ;
        make.top.equalTo(self.view.mas_top) ;
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    [_alphaview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_specView.mas_left) ;
        make.right.equalTo(_specView.mas_right) ;
        make.top.equalTo(_specView.mas_top) ;
        make.height.equalTo(@200);
    }];
    [_specContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_specView.mas_left) ;
        make.right.equalTo(_specView.mas_right) ;
        make.top.equalTo(_alphaview.mas_bottom) ;
        make.bottom.equalTo(_specView.mas_bottom);
    }];
    [_specImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_specContentView.mas_left).with.offset(10) ;
        make.width.equalTo(@70) ;
        make.height.equalTo(@70) ;
        make.top.equalTo(_specContentView.mas_top).with.offset(20);
    }];
    [_specProductNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_specImageView.mas_right).with.offset(8) ;
        make.right.equalTo(_specContentView.mas_right) ;
        
        make.top.equalTo(_specImageView.mas_top);
        make.height.equalTo(@21) ;
    }];
    [_specPriceScopeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_specImageView.mas_right).with.offset(8) ;
        make.right.equalTo(_specCountLabel.mas_left) ;
        
        make.bottom.equalTo(_specImageView.mas_bottom);
        make.height.equalTo(@21) ;
    }];
    [_specCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_specContentView.mas_right).with.offset(-15) ;
        make.left.equalTo(_specPriceScopeLabel.mas_right) ;
        
        make.bottom.equalTo(_specImageView.mas_bottom);
        make.height.equalTo(@21) ;
    }];
    
    [_specLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_specContentView.mas_right).with.offset(-10) ;
        make.left.equalTo(_specContentView.mas_left).with.offset(10) ;
        
        make.top.equalTo(_specImageView.mas_bottom).with.offset(20);
        make.height.equalTo(@1) ;
    }];
    
    [_specSelectTag mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.left.equalTo(_specContentView.mas_left).with.offset(10) ;
        
        make.top.equalTo(_specLineLabel.mas_bottom).with.offset(25);
        make.height.equalTo(@21) ;
    }];
    [_specLineLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_specContentView.mas_right).with.offset(-10) ;
        make.left.equalTo(_specContentView.mas_left).with.offset(10) ;
        
        make.top.equalTo(_specSelectTag.mas_bottom).with.offset(10);
        make.height.equalTo(@1) ;
    }];
    
    [_specListTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_specContentView.mas_right).with.offset(-10) ;
        make.left.equalTo(_specContentView.mas_left).with.offset(10) ;
        
        make.top.equalTo(_specLineLabel2.mas_bottom);
        make.bottom.equalTo(_specConfirmBtn.mas_top) ;
    }];
    
    [_specConfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_specContentView.mas_left) ;
        make.right.equalTo(_specContentView.mas_right) ;
        make.bottom.equalTo(_specView.mas_bottom) ;
        make.height.equalTo(@45);
    }];
    
    [_specCloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@30);
        make.right.equalTo(_specContentView.mas_right).with.offset(-20) ;
        
        make.top.equalTo(_specContentView.mas_top).with.offset(-15);
        make.height.equalTo(@30) ;
    }];
    
}
-(void)setNavigation
{
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    self.navigationController.navigationBarHidden=NO;
  
    
    UIButton*edit = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 30, 30)];
    [edit setImage:[UIImage imageNamed:@"bianji"] forState:UIControlStateNormal];
    [edit addTarget:self action:@selector(editBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIBarButtonItem* myBtnBtn1 = [[UIBarButtonItem alloc] initWithCustomView:edit];
    
   
    self.navigationItem.rightBarButtonItem = myBtnBtn1;
    
}
- (void)BackAction  {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)editBtnClick  {
    BusinessCombinationAddViewController *addVC=[[BusinessCombinationAddViewController alloc] init];
    
    addVC.titleName=_titleStr;
    addVC.styleID=_itemTypeCodeStr;
    addVC.cbID=_cbIdStr;
    addVC.editOrAddString=@"Edit";
    addVC.styleName=_itemTypeNameStr;
    addVC.detailDescriptionStr=_detailStr;
    commdity.content=_itemTypeNameStr;
    addVC.topImageViewArray=[NSMutableArray arrayWithArray:topImageArray];
    addVC.topImageViewHalfArray=[NSMutableArray arrayWithArray:topImageHalfArray];
    addVC.bottomIDArray=[NSMutableArray arrayWithArray:subItemIDArray];
    addVC.bottomImageArray=[NSMutableArray arrayWithArray:subItemUrlArray];
    // addVC.bottomImageHalfArray=[NSMutableArray arrayWithArray:subItemUrlHalfArray];
    [self.navigationController pushViewController:addVC animated:YES];
    
   // NSLog(@"_itemTypeNameStr===%@",_itemTypeNameStr);
}


@end
